<?php

namespace App\Jobs;
use App\Models\Search;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class SearchJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    private $user_id;
    private $keyword;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($user_id, $keyword)
    {
        $this->user_id = $user_id;
        $this->keyword = $keyword;
    }

    /**
     * Execute the job.
     * @link https://shimo.im/mindmaps/y6ydprxxxJKCggPx/
     * @return void
     */
    public function handle()
    {
        if (!$this->keyword)
            return;
        Search::create([
            'user_id' => $this->user_id,
            'keyword' => $this->keyword
        ]);
    }
}
